<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport"
        content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no, viewport-fit=cover" />
    <title>诚赉健康</title>
    <link rel="stylesheet" href="../css/vant.css">
    <link rel="stylesheet" href="./css/userInfo.css">
</head>

<body>
    <div id="app" v-cloak>
        <div class="loading" v-if="mask">
            <img src="../img/load.gif">
        </div>
        <div class="conBox">

            <div class="formCon">
                <img src="./img/infoTop.png" class="infoTop" alt="">
                <img src="./img/infoBottom.png" class="infoBottom" alt="">
                <div>
                    <span>姓名</span>
                    <input type="text" v-model="userInfo.userName" placeholder="请输入姓名">
                </div>
                <div>
                    <span>电话</span>
                    <input type="number" v-model="userInfo.userPhone" placeholder="请输入电话">
                </div>
                <!--  -->
                <div v-if="userInfo.userStatus==2">
                    <span>业务员</span>
                    <input type="text" v-model="saleManName" placeholder="请绑定业务员" readonly @click="selectHandle">
                </div>
                <div class="lastInfoBox">
                    <span>地址</span>
                    <input type="text" v-model="userInfo.userAddress" placeholder="请选择地区" readonly
                        @click="addressDialog=true">
                    <input type="text" class="addressDetail" v-model="userInfo.stay" placeholder="请输入详细地址">
                </div>
            </div>
            <div class="saveInfoBtn" @click="toSubmit">签到保存</div>

        </div>



        <van-popup v-model="addressDialog" round position="bottom">
            <van-cascader v-model="cityValue" title="请选择城市" :options="cityData3" @close="addressDialog = false"
                @finish="onFinish" />
        </van-popup>

        <!--  用户绑定业务员 -->
        <van-action-sheet v-model="showAction" description="请绑定您的业务员" :actions="saleManList" @select="onSelect" />
    </div>


    <script src="../js/vue.min.js"></script>
    <script src="../js/flex_ible/lib-flexible.js"></script>
    <script src="../js/vue-lazyload.js"></script>
    <script src="../js/vant.min.js"></script>
    <script src="../js/vue-lazyload.js"></script>
    <script src="../js/mui.min.js"></script>
    <script src="../js/url.js" type="text/javascript" charset="utf-8"></script>
    <script src="./js/url.js" type="text/javascript" charset="utf-8"></script>
    <script src="../js/ajax.js"></script>
    <script src="../js/city.data-3.js"></script>
    <script type="text/javascript" src="https://res2.wx.qq.com/open/js/jweixin-1.6.0.js"></script>
    <script>

        var vm = new Vue({
            el: "#app",
            data: {
                userInfo: {
                    userName: '',
                    userPhone: '',
                    userAddress: '',
                },
                mask: false,
                userStatus: '', //  1 业务员  2 客户
                saleManId: '',//用户绑定业务员的id
                saleManName: '',//用户绑定业务员的名称
                addressDialog: false,// 选择地址
                // 城市信息
                cityValue: '',

                showAction: false,// 选择业务员

                saleManList: [],//业务员列表
            },
            created() {
                this.getSalesmanList()

            },
            methods: {

                // 选择绑定的业务员
                onSelect(item) {
                    console.log(item);

                    this.saleManId = item.id
                    this.saleManName = item.name

                    console.log(this.saleManId);
                    console.log(this.saleManName);

                    this.showAction = false

                },
                // 选择身份
                selectHandle() {
                    if (this.userInfo.salesman) {
                        this.$toast('业务员已绑定，不可修改')
                        return
                    }
                    this.showAction = true
                },

                // 提交
                toSubmit() {
                    if (this.userInfo.userName == '') {
                        this.$toast('请输入姓名')
                        return
                    }
                    if (!this.checkText(this.userInfo.userName)) {
                        this.$toast('姓名应为纯中文字符')
                        return
                    }
                    if (this.userInfo.userPhone == '') {
                        this.$toast('请输入手机号')
                        return
                    }
                    if (!this.validator(this.userInfo.userPhone)) {
                        this.$toast('请输入正确的手机号')
                        return
                    }

                    if (this.userStatus == 2 && this.saleManId == '') {
                        this.$toast('请选择业务员')
                        return
                    }
                    if (this.userInfo.userAddress == '') {
                        this.$toast('请选择地区')
                        return
                    }
                    if (this.userInfo.stay == '') {
                        this.$toast('请输入详细地址')
                        return
                    }
                    console.log(this.userInfo);

                    var that = this;
                    that.mask = true;
                    ajax({
                        url: newUrl4 + "/meeting/editSignin",
                        type: 'post',
                        data: {
                            signinId: that.userInfo.signinId,
                            openId: that.userInfo.openId,
                            userName: that.userInfo.userName,
                            userPhone: that.userInfo.userPhone,
                            userAddress: that.userInfo.userAddress,
                            stay: that.userInfo.stay,
                            userStatus: that.userInfo.userStatus,
                            salesman: that.userInfo.userStatus == 2 ? that.saleManId : '',
                            flag: 0,
                            awardId: -1,
                            chanceType: that.userInfo.userStatus == 1 ? 1 : 0
                        },
                        dataType: 'json',
                        timeout: 10000,
                        contentType: "application/json",
                        success: function (res) {
                            console.log(res);
                            var res = JSON.parse(res)
                            if (res.flag) {
                                console.log(res);
                                that.$toast('保存成功')
                                that.mask = false
                                localStorage.signinUserId = that.userInfo.signinId
                                window.location.replace("https://open.weixin.qq.com/connect/oauth2/authorize?appid=wxe50be6288d63a04c&redirect_uri=https://www.ccclkj.cn/sharepage/51Active/index.html&response_type=code&scope=snsapi_base&state=2#wechat_redirect")
                            } else {
                                that.mask = false
                                that.$toast('保存失败，请重试')
                            }
                        },
                    })
                },
                onFinish(obj) {
                    var that = this;
                    console.log(obj);
                    var arr = []
                    obj.selectedOptions.forEach(item => {
                        arr.push(item.text)
                        that.userInfo.userAddress = arr.join('')
                    })
                    console.log(arr);
                    console.log(that.userInfo.userAddress);

                    this.addressDialog = false
                },


                getManName(id) {
                    var that = this;
                    that.saleManList.forEach(item => {
                        if (item.id == id) {
                            that.saleManName = item.name
                        }
                    })
                },
                // 获取业务员列表
                getSalesmanList() {
                    var _this = this;
                    _this.mask = true;
                    ajax({
                        url: newUrl4 + "meeting/getSigninList",
                        type: 'post',
                        data: {
                            // salesman: 0,
                            flag: 0
                        },
                        dataType: 'json',
                        timeout: 10000,
                        contentType: "application/json",
                        success: function (res) {
                            // console.log(res);
                            var res = JSON.parse(res)
                            if (res.flag) {
                                // console.log(res);
                                res.data = res.data.filter(item => {
                                    return item.userStatus == 1
                                })
                                _this.saleManList = []
                                res.data.forEach(item => {
                                    _this.saleManList.push({
                                        name: item.userName,
                                        id: item.signinId
                                    })
                                })
                                // _this.getInfo()
                                // alert(localStorage.signinUser)
                                _this.userInfo = JSON.parse(localStorage.signinUser)

                                _this.getManName(_this.userInfo.salesman)
                            }
                            _this.mask = false
                        },
                    })
                },

                validator: function (val) {
                    return /^(?:(?:\+|00)86)?1(?:(?:3[\d])|(?:4[5-79])|(?:5[0-35-9])|(?:6[5-7])|(?:7[0-8])|(?:8[\d])|(?:9[189]))\d{8}$/.test(val) || /^(?:(?:\d{3}-)?\d{8}|^(?:\d{4}-)?\d{7,8})(?:-\d+)?$/.test(val);
                },

                checkText(str) {
                    var reg = new RegExp("[\\u4E00-\\u9FFF]+", "g")
                    if (!reg.test(str)) {
                        return false;
                    } else {
                        return true;
                    }
                },
            }
        })

    </script>

</body>

</html>